home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / genconfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-01  |  6.2 KB  |  277 lines  |  [TEXT/KAHL]

  1. /* Generate from machine description:
  2.  
  3.    - some #define configuration flags.
  4.    Copyright (C) 1987 Free Software Foundation, Inc.
  5.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 1, or (at your option)
  12. any later version.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with GNU CC; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include "config.h"
  26. #include "rtl.h"
  27. #include "obstack.h"
  28.  
  29. struct obstack obstack;
  30. struct obstack *rtl_obstack = &obstack;
  31.  
  32. #define obstack_chunk_alloc xmalloc
  33. #define obstack_chunk_free free
  34. extern int xmalloc ();
  35. extern void free ();
  36.  
  37. /* flags to determine output of machine description dependent #define's.  */
  38. int max_recog_operands_flag;
  39. int max_dup_operands_flag;
  40. int max_clobbers_per_insn_flag;
  41. int register_constraint_flag;
  42.  
  43. int clobbers_seen_this_insn;
  44. int dup_operands_seen_this_insn;
  45.  
  46. void fatal ();
  47. void fancy_abort ();
  48.  
  49. void
  50. walk_insn_part (part)
  51.      rtx part;
  52. {
  53.   register int i, j;
  54.   register RTX_CODE code;
  55.   register char *format_ptr;
  56.  
  57.   if (part == 0)
  58.     return;
  59.  
  60.   code = GET_CODE (part);
  61.   switch (code)
  62.     {
  63.     case CLOBBER:
  64.       clobbers_seen_this_insn++;
  65.       break;
  66.  
  67.     case MATCH_OPERAND:
  68.       if (XINT (part, 0) > max_recog_operands_flag)
  69.     max_recog_operands_flag = XINT (part, 0);
  70.       if (XSTR (part, 2) && *XSTR (part, 2))
  71.     register_constraint_flag = 1;
  72.       return;
  73.  
  74.     case MATCH_OPERATOR:
  75.       if (XINT (part, 0) > max_recog_operands_flag)
  76.     max_recog_operands_flag = XINT (part, 0);
  77.       /* Now scan the rtl'x in the vector inside the match_operator.  */
  78.       break;
  79.  
  80.     case LABEL_REF:
  81.       if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
  82.     break;
  83.       return;
  84.  
  85.     case MATCH_DUP:
  86.       ++dup_operands_seen_this_insn;
  87.       if (XINT (part, 0) > max_recog_operands_flag)
  88.     max_recog_operands_flag = XINT (part, 0);
  89.  
  90.     case REG: case CONST_INT: case SYMBOL_REF:
  91.     case PC: case CC0:
  92.       return;
  93.     }
  94.  
  95.   format_ptr = GET_RTX_FORMAT (GET_CODE (part));
  96.  
  97.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
  98.     switch (*format_ptr++)
  99.       {
  100.       case 'e':
  101.       case 'u':
  102.     walk_insn_part (XEXP (part, i));
  103.     break;
  104.       case 'E':
  105.     if (XVEC (part, i) != NULL)
  106.       for (j = 0; j < XVECLEN (part, i); j++)
  107.         walk_insn_part (XVECEXP (part, i, j));
  108.     break;
  109.       }
  110. }
  111.  
  112. void
  113. gen_insn (insn)
  114.      rtx insn;
  115. {
  116.   int i;
  117.  
  118.   /* Walk the insn pattern to gather the #define's status.  */
  119.   clobbers_seen_this_insn = 0;
  120.   dup_operands_seen_this_insn = 0;
  121.   if (XVEC (insn, 1) != 0)
  122.     for (i = 0; i < XVECLEN (insn, 1); i++)
  123.       walk_insn_part (XVECEXP (insn, 1, i));
  124.  
  125.   if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
  126.     max_clobbers_per_insn_flag = clobbers_seen_this_insn;
  127.   if (dup_operands_seen_this_insn > max_dup_operands_flag)
  128.     max_dup_operands_flag = dup_operands_seen_this_insn;
  129. }
  130.  
  131. /* Similar but scan a define_expand.  */
  132.  
  133. void
  134. gen_expand (insn)
  135.      rtx insn;
  136. {
  137.   int i;
  138.  
  139.   /* Walk the insn pattern to gather the #define's status.  */
  140.  
  141.   /* Note that we don't bother recording the number of MATCH_DUPs
  142.      that occur in a gen_expand, because only reload cares about that.  */
  143.   if (XVEC (insn, 1) != 0)
  144.     for (i = 0; i < XVECLEN (insn, 1); i++)
  145.       {
  146.     /* Compute the maximum SETs and CLOBBERS
  147.        in any one of the sub-insns;
  148.        don't sum across all of them.  */
  149.     clobbers_seen_this_insn = 0;
  150.  
  151.     walk_insn_part (XVECEXP (insn, 1, i));
  152.  
  153.     if (clobbers_seen_this_insn > max_clobbers_per_insn_flag)
  154.       max_clobbers_per_insn_flag = clobbers_seen_this_insn;
  155.       }
  156. }
  157.  
  158. void
  159. gen_peephole (peep)
  160.      rtx peep;
  161. {
  162.   int i;
  163.  
  164.   /* Look through the patterns that are matched
  165.      to compute the maximum operand number.  */
  166.   for (i = 0; i < XVECLEN (peep, 0); i++)
  167.     walk_insn_part (XVECEXP (peep, 0, i));
  168. }
  169.  
  170. int
  171. xmalloc (size)
  172. {
  173.   register int val = (int)malloc (size);
  174.  
  175.   if (val == 0)
  176.     fatal ("virtual memory exhausted");
  177.  
  178.   return val;
  179. }
  180.  
  181. int
  182. xrealloc (ptr, size)
  183.      char *ptr;
  184.      int size;
  185. {
  186.   int result = (int)realloc (ptr, size);
  187.   if (!result)
  188.     fatal ("virtual memory exhausted");
  189.   return result;
  190. }
  191.  
  192. void
  193. fatal (s, a1, a2)
  194.      char *s;
  195. {
  196.   fprintf (stderr, "genconfig: ");
  197.   fprintf (stderr, s, a1, a2);
  198.   fprintf (stderr, "\n");
  199.   exit (FATAL_EXIT_CODE);
  200. }
  201.  
  202. /* More 'friendly' abort that prints the line and file.
  203.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  204.  
  205. #ifdef MPW
  206. #include <Types.h>
  207. #endif /* MPW */
  208.  
  209. void
  210. fancy_abort ()
  211. {
  212. #ifdef MPW
  213.   /* This gets to Macsbug so we can maybe figure out what happened. */
  214.   Debugger();
  215. #endif /* MPW */
  216.   fatal ("Internal gcc abort.");
  217. }
  218.  
  219. int
  220. main (argc, argv)
  221.      int argc;
  222.      char **argv;
  223. {
  224.   rtx desc;
  225.   FILE *infile;
  226.   extern rtx read_rtx ();
  227.   register int c;
  228.  
  229.   obstack_init (rtl_obstack);
  230.  
  231.   if (argc <= 1)
  232.     fatal ("No input file name.");
  233.  
  234.   infile = fopen (argv[1], "r");
  235.   if (infile == 0)
  236.     {
  237.       perror (argv[1]);
  238.       exit (FATAL_EXIT_CODE);
  239.     }
  240.  
  241.   init_rtl ();
  242.  
  243.   printf ("/* Generated automatically by the program `genconfig'\n\
  244. from the machine description file `md'.  */\n\n");
  245.  
  246.   /* Read the machine description.  */
  247.  
  248.   while (1)
  249.     {
  250.       c = read_skip_spaces (infile);
  251.       if (c == EOF)
  252.     break;
  253.       ungetc (c, infile);
  254.  
  255.       desc = read_rtx (infile);
  256.       if (GET_CODE (desc) == DEFINE_INSN)
  257.     gen_insn (desc);
  258.       if (GET_CODE (desc) == DEFINE_EXPAND)
  259.     gen_expand (desc);
  260.       if (GET_CODE (desc) == DEFINE_PEEPHOLE)
  261.     gen_peephole (desc);
  262.     }
  263.  
  264.   /* 3 more than needed for this md file, for the sake of asm constructs.  */
  265.   printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands_flag + 4);
  266.  
  267.   if (max_dup_operands_flag == 0)
  268.     max_dup_operands_flag = 1;
  269.   printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands_flag);
  270.  
  271.   if (register_constraint_flag)
  272.     printf ("#define REGISTER_CONSTRAINTS\n");
  273.  
  274.   fflush (stdout);
  275.   exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  276. }
  277.